#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include <string>

using namespace std;

string toHex(pthread_t tid)
{
    char hex[64];
    snprintf(hex, sizeof(hex), "%p", tid);
    return hex;
}

void* threadRoutine(void* args)
{
    const char* name = static_cast<const char*>(args);
    while(true)
    {
        cout << name << ", id: " << toHex(pthread_self()) << endl;
        sleep(1);
    }

    return nullptr;
}

int main()
{
    // 打印出来很大的这个线程id是什么呢？
    pthread_t tid;
    pthread_create(&tid, nullptr, threadRoutine, (void*)"thread 1");

    cout << "main thread create new thread tid: " << toHex(tid) << endl; 

    pthread_join(tid, nullptr);
    return 0;
}